import {
  addCompanyFont,
  changeCompanyAdmin,
  delCompanyAdmin,
  delCompanyFont,
  getCompanyAdminList,
  getCompanyChAdmin,
  getCompanyInfo,
  getCompanyRole,
  getCompanySet,
  getCurrentAdmin,
  putCompanyFont,
  putCompanyInfo,
  putCompanyRole,
  setCompanyAdmin
} from '@/api/company'

const state = {
  attendanceList: {},
}

const mutations = {
  SET_ATTENDANCELIST: (state, data) => {
    state.attendanceList = data
  }
}

const actions = {
  // 保存企业信息
  putCompanyInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putCompanyInfo(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取企业信息
  getCompanyInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getCompanyInfo(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取通讯录设置
  getCompanySetAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getCompanySet(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },  // 获取通讯录设置
  getCurrentAdmin({ commit }) {
    return new Promise((resolve, reject) => {
      getCurrentAdmin().then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加通讯录字段
  addCompanyFontAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addCompanyFont(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除通讯录字段
  delCompanyFontAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delCompanyFont(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 修改通讯录字段
  putCompanyFontAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putCompanyFont(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更换主管理员
  changeCompanyAdminAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      changeCompanyAdmin(params).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取权限列表
  getCompanyAdminListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getCompanyAdminList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取角色列表
  getCompanyRoleAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getCompanyRole(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更改角色
  putCompanyRoleAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putCompanyRole(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取子管理员列表
  getCompanyChAdminAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getCompanyChAdmin(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除子管理员
  delCompanyAdminAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delCompanyAdmin(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 设置子管理员
  setCompanyAdminAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      setCompanyAdmin(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

